package gemini.castor.ui.client.page.widget.productlist;

import gemini.basic.model.Product;

import com.google.gwt.event.shared.GwtEvent;

public class ProductListEvent extends GwtEvent<ProductListHandler> {

	private static Type<ProductListHandler> TYPE;
	
	public static Type<ProductListHandler> getType() {
		if (TYPE == null)
			TYPE = new Type<ProductListHandler>();
		return TYPE;
	}
	
	public enum ForwardType {
		SELECT_PRODUCT;
	}
	
	public ProductListEvent(ForwardType forwardType) {
		super();
		this.setForwardType(forwardType);
	}
	
	private ForwardType forwardType;
	private Product selectedProduct;

	@Override
	protected void dispatch(ProductListHandler handler) {
		if(forwardType.equals(ForwardType.SELECT_PRODUCT)){
			handler.onSelectedProduct(this);
		}
	}
	
	@Override
	public Type<ProductListHandler> getAssociatedType() {
		return getType();
	}

	public void setForwardType(ForwardType forwardType) {
		this.forwardType = forwardType;
	}

	public ForwardType getForwardType() {
		return forwardType;
	}

	public void setSelectedProduct(Product selectedProduct) {
		this.selectedProduct = selectedProduct;
	}

	public Product getSelectedProduct() {
		return selectedProduct;
	}
}
